package doublePointer;

public class JudgeSquareSum {

    /**
     * LeetCode T633 平方数之和
     * 给定一个非负整数 c ，你要判断是否存在两个整数 a 和 b，使得 a2 + b2 = c 。
     * 提示：两数之和的变形题目
     * @param args
     */
    public static void main(String[] args) {
        double i = 1.9;
        System.out.println(Math.sqrt(0));
    }

    //使用双指针解决此问题
    public boolean judgeSquareSum(int c) {
        int high = (int)Math.sqrt(c) + 1;
        int low = 0;
        while (low <= high){
            int temp = low*low + high*high;
            if (temp == c){
                return true;
            } else if (temp > c){
                high--;
            } else {
                low++;
            }
        }
        return false;
    }
}
